package com.edu.dsai.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.bean.BeanUtil;
import com.edu.dsai.domain.History;
import com.edu.dsai.dto.HistoryOutput;
import com.edu.dsai.service.HistoryService;
import com.edu.dsai.utils.R;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@RestController
@RequestMapping("/history")
@SaCheckLogin

public class HistoryController {
    @Resource
    private HistoryService historyService;
    @GetMapping("/all")

    public R<List<HistoryOutput>> getAllData() {
        Object  username = StpUtil.getLoginId();
        List<History> list = historyService.getAllData(username);
        List<HistoryOutput> historyOutputs = BeanUtil.copyToList(list, HistoryOutput.class);
        return R.ok(historyOutputs);
    }
}
